package myclient;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;

import javax.swing.JOptionPane;
import javax.swing.tree.TreeNode;
/**
 * @author JIAO
 */
public class PersonalSetting implements ActionListener{
	PrintWriter writer;
	public PersonalSetting(PrintWriter writer) {
		this.writer = writer;
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("+")){
			System.out.println("+");
			String id = JOptionPane.showInputDialog("请输入添加好友的号码！");
			if(id==null)
				return;
			try {
				Integer.parseInt(id);
				writer.println("server");
				writer.println("addFriend");
				writer.println(id);
				System.out.println("已经向服务器发送好友添加请求！"+id);
			} catch (NumberFormatException e1) {
				JOptionPane.showMessageDialog(null, "您输入的有非法字符！");
			}
		}else if(e.getActionCommand().equals("-")){
			System.out.println("-");
			if(MyTreeSelectionListener.path==null){
				JOptionPane.showMessageDialog(null,"请选择一个好友");
				return;
			}
			TreeNode node = (TreeNode)MyTreeSelectionListener.path.getLastPathComponent();
			String id = node.toString();
			System.out.println("node id:"+id);
			writer.println("server");
			writer.println("deleteFriend");
			writer.println(id);
		}else if(e.getActionCommand().equals("icon")){
			System.out.println("icon");
			
		}
		
	}
	

}
